﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using log4net;
using RealState.BLL;
using RealState.BusinessObjects;
using RealState.Utils;

namespace RealState.W.AdminControl
{
    public partial class ContentTypeE : System.Web.UI.UserControl
    {
        private ContentTypesBLL m_ContentTypeBLL;
        private ContentTypes m_ContentTypeDO;
        protected ILog log = LogManager.GetLogger(typeof(ContentTypeE));
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                loadData();
            }
        }

        private void loadData()
        {
            m_ContentTypeBLL = new ContentTypesBLL();
            m_ContentTypeDO = new ContentTypes();
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
                {
                    m_ContentTypeDO = m_ContentTypeBLL.GetContentTypes(Int32.Parse(Request.QueryString["ID"]));
                    txtTitle.Text = m_ContentTypeDO.Title;
                    drpGroup.SelectedValue = m_ContentTypeDO.GroupId.ToString();

                }

            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
            finally
            {
                m_ContentTypeBLL = null;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            m_ContentTypeBLL = new ContentTypesBLL();
            m_ContentTypeDO = new ContentTypes();
            try
            {
                m_ContentTypeDO.ID = Int32.Parse(Request.QueryString["ID"]);
                m_ContentTypeDO.Title = txtTitle.Text;
                m_ContentTypeDO.GroupId = Int32.Parse(drpGroup.SelectedValue);
                int result = m_ContentTypeBLL.UpdateContentTypes(m_ContentTypeDO);
                if (result > 0)
                {
                    JavaScript.Success("Cập nhật thành công", Page, "ContentType.aspx");
                }
                else
                    JavaScript.Error("Có lỗi xảy ra ", Page);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
            finally
            {
                m_ContentTypeBLL = null;
                m_ContentTypeDO = null;
            }
        }


    }
}